<template>
  <div class="team_center">
    <div
      class="team_card"
      v-for="(studentData, i) in studentList"
      :key="studentData.s_id"
    >
      <div class="tc_photo">
        <img src="../../assets/img/logo.png" alt="" />
        <span>{{ studentData.s_name }}</span>
      </div>
      <div>
        <ul class="tc_mes">
          <li>
            学号：<span>{{ studentData.s_shoolId }}</span>
          </li>
          <li>
            专业：<span>{{ studentData.s_major }}</span>
          </li>
          <li>
            班级：<span>{{ studentData.s_classname }}</span>
          </li>
          <li>
            电话：<span>{{ studentData.s_phone }}</span>
          </li>
          <li>
            邮件：<span>{{ studentData.s_eMail }}</span>
          </li>
        </ul>
      </div>
      <div>
        <el-button
          size="small "
          type="primary"
          round
          @click="inStudentRoom(studentData.s_id)"
          >进入空间</el-button
        >
        <el-button size="small " type="success" @click="openamendInf(i)" round
          >修改信息</el-button
        >
      </div>
    </div>
    <el-dialog title="修改信息" :visible.sync="dialogFormVisible">
      <ul class="tc_mes">
        <li>
          姓名：<input
            type="text"
            v-model="studentList[indexStudent].s_name"
          />
        </li>
        <li>
          学号：<input
            type="text"
            v-model="studentList[indexStudent].s_shoolId"
          />
        </li>
        <li>
          专业：<input
            type="text"
            v-model="studentList[indexStudent].s_major"
          />
        </li>
        <li>
          班级：<input
            type="text"
            v-model="studentList[indexStudent].s_classname"
          />
        </li>
        <li>
          电话：<input
            type="text"
            v-model="studentList[indexStudent].s_phone"
          />
        </li>
        <li>
          邮件：<input
            type="text"
            v-model="studentList[indexStudent].s_eMail"
          />
        </li>
      </ul>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelamendInf">取 消</el-button>
        <el-button type="primary" @click="amendInf">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      studentList: [],
      dialogFormVisible: false,
      indexStudent: 1,
    };
  },
  mounted() {
    this.getStudentList();
  },
  methods: {
    getStudentList() {
      axios.post(`http://localhost:3000/getStudentList`, {}).then((ret) => {
        this.studentList = ret.data.studentList;
      });
    },
    inStudentRoom(id) {
      this.$router.push({ path: "/Administrator/StudentInf", query: { student_id: id } });
    },
    cancelamendInf() {
      this.dialogFormVisible = false;
    },
    openamendInf(id) {
      this.dialogFormVisible = true;
      this.indexStudent = id;
    },
    amendInf() {
      axios.post(`http://localhost:3000/updateStudent`, {studentData:this.studentList[this.indexStudent]}).then((ret) => {
        if(ret.data.code ==1){
          this.$message({
              showClose: true,
              message: "修改成功",
              type: "success",
            });
            this.cancelamendInf()
        }
      });
    },
  },
};
</script>

<style scoped>
.team_center {
  padding: 20px;
}
.team_card {
  width: 85%;
  height: 100px;
  margin: 20px auto;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 20px;
  border: 1xp solid #ddd;
  background-color: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(5px);
  border-left: 2px solid rgba(255, 255, 255, 0.5);
  border-top: 2px solid rgba(255, 255, 255, 0.5);
}
.tc_photo {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tc_photo > img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid #40c9c6;
}
.tc_mes {
  width: 600px;
  margin-left: 50px;
  display: flex;
  flex-wrap: wrap;
  justify-content: left;
}
.tc_mes > li {
  width: 40%;
  font-size: 14px;
  color: #606266;
  letter-spacing: 1px;
  margin-bottom: 5px;
}
.tc_mes > li > span {
  padding: 0 5px;
}

</style>
